#include <stdio.h>
#include <math.h>
#include <mpi.h>

#define LOOP_LIMIT 1000000000 
int main(int argc, char **argv){
	int numprocs=0, rank=0, namelen=0;
	char processor_name[MPI_MAX_PROCESSOR_NAME];

	double result=0.0;
	int i=0, source=0;

	MPI_Status status;

	MPI_Init(&argc,&argv);
	MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
	MPI_Get_processor_name(processor_name, &namelen);


	if (rank != 0){
		fprintf(stdout, "%d:\n", rank);
		for (i=0;i<LOOP_LIMIT;i++){
			result+=sqrt(9);
		}
		MPI_Send(&result,sizeof(double),MPI_DOUBLE,0,0,MPI_COMM_WORLD);
	} else {
		fprintf(stdout, "%d:\n", rank);
		for(source=1;source<numprocs;source++){
			MPI_Recv(&result,sizeof(double),MPI_DOUBLE,source,0,MPI_COMM_WORLD,&status);
			fprintf(stdout,"From %d, result=%f\n",source,result);
		}
	}


	MPI_Finalize();
	return 0;
}
